using System;
using System.Collections.Generic;
using System.Text;

using Mud.Common.Physical;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using System.Windows.Media;

namespace Mud.Client.WPF.Graphics
{

    /// <summary>
    /// Represents a model of one land square
    /// </summary>
    public class LandSquareModel : Model
    {

        public AreaLandSquare LandSquare
        {
            get { return _landSquare; }
        }
        private AreaLandSquare _landSquare;


        public LandSquareModel(Viewport3D viewport3D, AreaLandSquare land)
            : base(viewport3D)
        {
            _landSquare = land;
            this.ModelVisual3D = new ModelVisual3D();
            MeshGeometry3D mesh = new MeshGeometry3D();
            mesh.Positions.Add(new Point3D(-0.5, -0.5, 0));
            mesh.Positions.Add(new Point3D(0.5, -0.5, 0));
            mesh.Positions.Add(new Point3D(0.5, 0.5, 0));
            mesh.Positions.Add(new Point3D(-0.5, 0.5, 0));
            mesh.TriangleIndices.Add(3);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);

            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);
            mesh.TriangleIndices.Add(3);

            GeometryModel3D model = new GeometryModel3D(mesh, GetTerrainMaterial(_landSquare.TerrainType));
            this.ModelVisual3D.Content = model;
            this.ModelVisual3D.Transform = new TranslateTransform3D(land.X, land.Y, 0);
        }

        public Material GetTerrainMaterial(TerrainType type)
        {
            switch (type)
            {
                case TerrainType.Grass:
                    return new DiffuseMaterial(Brushes.Green);

                case TerrainType.Dirt:
                    return new DiffuseMaterial(Brushes.Brown);

                case TerrainType.Stone:
                    return new DiffuseMaterial(Brushes.Gray);

                case TerrainType.Water:
                    return new DiffuseMaterial(Brushes.CornflowerBlue);

                case TerrainType.Ice:
                    return new DiffuseMaterial(Brushes.LightCyan);

                case TerrainType.Sand:
                    return new DiffuseMaterial(Brushes.Yellow);

                case TerrainType.Void:
                    return new DiffuseMaterial(Brushes.MidnightBlue);

                default:
                    return new DiffuseMaterial(Brushes.Black);

            }
        }

    }
}
